package br.ufrj.dcc.dojo.jtrace.texture;

import java.io.IOException;

import org.jtrace.primitives.Point2D;
import org.jtrace.primitives.Vector3D;

public class CylinderTextureShader extends TextureShader {

	public CylinderTextureShader(String filename) throws IOException {
		super(filename);
	}

	@Override
	public Point2D getPoint2DFromMapping(Vector3D vector, double height) {
		
		double HALFPI = Math.PI/2;
		
		double u =  vector.getZ() / height;
		if (u < 0) u = 1 + u;
    	
		double v = Math.atan( vector.getY() / vector.getX()); 
    	v = (v + HALFPI) / Math.PI;
    	
    	System.out.println("Pontos do mapeamento esferico: " + u + " , " + v);
    	System.out.println("Altura: " + height);
		return new Point2D(u, v);
	}

}